package com.mastercard.labs

import static org.junit.Assert.*

import org.junit.Before;

import grails.test.mixin.support.*

class UserServicesTest {

	def userService
	
	void testGetUserById() {
		println("--------- getUserById ----------")
		def usr = userService.getUserById(1)
        assert usr.username != null && !usr.username.trim().equals("")
    }
	
	void testSearchUserByCondition(){
		println("--------- searchUserByCondition ----------")
		def list = userService.searchUserByCondition("ADMIN", null, null, null)
		assert list.size() > 0
		
		if(list.size() > 0){
			def usr = list.get(0)
			assert usr.nric == "S1234567D"
		}
	}
	
	void testSearchUserForDashboard(){
		println("---------- searchUserForDashboard ----------")
		def list = userService.searchUserForDashboard()
		assert list.size() == 5
		
		if(list.size() > 0){
			def usr = list.get(0)
			assert usr != null && usr.username != null && !usr.username.trim().equals("")
		}
	}
	
	void testSaveUser() {
		println("--------- testSaveUser ----------")
		def usr = userService.getUserById(1)
		usr.phone = "87654321"
		userService.saveUser(usr)
		
		def tmp = userService.getUserById(1)
		assert usr.phone == "87654321"
	}
}
